package ch.evaleto.gwt.media.client.player.ui;

import ch.evaleto.gwt.media.client.player.Media;
import ch.evaleto.gwt.media.client.player.Playlist;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.VerticalPanel;

public class PlaylistUI extends Composite {
	Grid grid;
	private Playlist playlist;
	public PlaylistUI() {
		grid=new Grid(0,6);
		grid.setBorderWidth(0);
		
		initWidget(grid);
	}
	

	public void update(Playlist playlist){
		this.playlist=playlist;
		
		grid.resizeRows(playlist.list().size());
		int i=0;for (Media m:playlist.list()){
			HorizontalPanel hp=new HorizontalPanel();
			VerticalPanel vp=new VerticalPanel();
			hp.setSpacing(6);
			hp.add(new HTML(m.getComment()));
			vp.add(hp);
			hp=new HorizontalPanel();
			hp.setSpacing(6);
			hp.add(new Hyperlink("tags",""));
			hp.add(new HTML("["+m.getUserTags()+"] "));
			hp.add(new Hyperlink("share",""));
			hp.add(new Hyperlink("schedule",m.getScheduleURL()));
			vp.add(hp);
			grid.setHTML(i,0,m.getName());
			grid.setWidget(i,1,vp);
			grid.setHTML(i,2,m.getVote());
			grid.setHTML(i,3,m.getLove());
			i++;
		}
	}
	public Playlist getPlaylist(){
		return playlist;
	}
}
